{include file = $smarty.const.APPLICATION_PATH|cat:"/application/views/header.html"}
{literal}
<script type="text/javascript">
    $(function(){
        $('.assortment').hover(function(){
            $('.assort_list').stop().fadeIn();
        },function(){
            $('.assort_list').stop().fadeOut();
        });
    });
    //添加用户
    $(function(){
        $('.popup_btn').click(function(){
                    var business_name =  $("input[name=business_name]").val();
                    $.ajax({
                        url:'/user/addBusiness',
                        data:{business_name:business_name},
                        type:'POST',
                        success:function(data){
                            var data = eval("("+data+")");
                            var code = data.code;
                            var msg = data.msg;
                            if(code == 4){
                                alert(msg);
                                return;
                            }
                            if(code == 3){
                                alert(msg);
                                window.location.reload();
                            }
                            if(code == 5){
                                alert(msg);
                                return;
                            }
                            if(code == 6){
                                alert(msg);
                                return;
                            }
                        },
                        dataType:'text'
                    });
        });
    });

    //切换公司时
    $(document).ready(function(){
           $('#select1').change(function(){
                var id=  $(this).children('option:selected').val();
            $.ajax({
                url:'/user/getCompany',
                data:{id:id},
                type:'POST',
                success:function(data){
                    var data = eval("("+data+")");
                        $("input[name=userid]").val(data.id);
                        $("input[name=business_phone]").val(data.business_phone);
                        $("input[name=main_variety]").val(data.main_variety);
                        $("input[name=contacts]").val(data.contacts);
                        $("input[name=mobile]").val(data.mobile);
                        $("input[name=phone]").val(data.phone);
                        $("input[name=qq]").val(data.qq);
                        $("input[name=business_addr]").val(data.business_addr);
                        if(data.is_default=="Y"){
                            $("input[name=is_default]").prop("checked",true);
                        }else {
                            $("input[name=is_default]").prop("checked",false);
                        }
                    if(data.business_province_id){
                        $('.business_province_id').append("<option value='"+ data.business_province_id+"' selected='selected'>"+ data.province_name +"</option>");
                    }
                    else{
                        $("#business_province_id").attr("value",'0');
                    }
                    if(data.business_city_id){
                        $('.business_city_id').append("<option value='"+ data.business_city_id+"' selected='selected'>"+ data.city_name +"</option>");
                    }
                    else{
                        $("#business_city_id").attr("value",'0');
                    }
                    if(data.business_area_id){
                        $('.business_area_id').append("<option value='"+ data.business_area_id+"' selected='selected'>"+ data.area_name +"</option>");
                    }
                    else{
                        $("#business_area_id").attr("value",'0');
                    }
                },
                dataType:'text'
            });
        });
    });

    //没点击公司名称时的数据
        $(function(){
            var id= $("#select1").val();
            $.ajax({
                url:'/user/getCompany',
                data:{id:id},
                type:'POST',
                success:function(data){
                    var data = eval("("+data+")");
                    $("input[name=userid]").val(data.id);
                    $("input[name=business_phone]").val(data.business_phone);
                    $("input[name=main_variety]").val(data.main_variety);
                    $("input[name=contacts]").val(data.contacts);
                    $("input[name=mobile]").val(data.mobile);
                    $("input[name=phone]").val(data.phone);
                    $("input[name=qq]").val(data.qq);
                    $("input[name=business_addr]").val(data.business_addr);
                    if(data.is_default=="Y"){
                        $("input[name=is_default]").prop("checked",true);
                    }else {
                        $("input[name=is_default]").prop("checked",false);
                    }
                    if(data.business_province_id){
                        $('.business_province_id').append("<option value='"+ data.business_province_id+"' selected='selected'>"+ data.province_name +"</option>");
                    }
                    else{
                        $("#business_province_id").attr("value",'0');
                    }
                    if(data.business_city_id){
                        $('.business_city_id').append("<option value='"+ data.business_city_id+"' selected='selected'>"+ data.city_name +"</option>");
                    }
                    else{
                        $("#business_city_id").attr("value",'0');
                    }
                    if(data.business_area_id){
                        $('.business_area_id').append("<option value='"+ data.business_area_id+"' selected='selected'>"+ data.area_name +"</option>");
                    }
                    else{
                        $("#business_area_id").attr("value",'0');
                    }
                },
                dataType:'text'
            });
        });
    //修改
    $(function(){
        $(".save_business").click(function(){
            var id =  $("input[name=userid]").val();
            var business_phone = $('input[name=business_phone]').val();
            var main_variety = $('input[name=main_variety]').val();
            var contacts = $('input[name=contacts]').val();
            var mobile = $('input[name=mobile]').val();
            var phone = $('input[name=phone]').val();
            var qq = $('input[name=qq]').val();
            var business_addr = $('input[name=business_addr]').val();
            var business_province_id=$("#business_province_id").val();
            var business_city_id=$("#business_city_id").val();
            var business_area_id=$("#business_area_id").val();
            var is_default=$("input[type=checkbox]:checked").val();
            $.ajax({
                url:'/user/updateById',
                data:{id:id,business_phone:business_phone,main_variety:main_variety,contacts:contacts,mobile:mobile,phone:phone,qq:qq,business_addr:business_addr,business_province_id:business_province_id,business_city_id:business_city_id,business_area_id:business_area_id,is_default:is_default},
                type:'POST',
                success:function(data){
                    var data = eval("("+data+")");
                    var code = data.code;
                    var msg = data.msg;

                    if(code == 99){
                        alert(msg);
                        return;
                    }

                    if(code == 2){
                        alert(msg);
                        return;
                    }
                    if(code == 3){
                        alert(msg);
                        return;
                    }
                    if(code == 4){
                        alert(msg);
                        return;
                    }
                    if(code == 5){
                        alert(msg);
                        return;
                    }
                    if(code == 6){
                        alert(msg);
                        return;
                    }
                    if(code == 1){
                        alert(msg);
                        window.location.reload();
                    }
                    if(code == 7){
                        alert(msg);
                        window.location.reload();
                    }


                },
                dataType:'text'
            });
        });
    });
    //省市区数据
    $(function() {
        $("#business_province_id").change(function () {
            var province_id = $("#business_province_id").val();
            if (province_id > 0) {
                $.ajax({
                    url: '/user/area',
                    data: {province_id: province_id},
                    type: 'POST',
                    success: function (data) {
                        var data = eval("(" + data + ")");
                        var str = '<option value="0">请选择....</option>';
                        $("#business_city_id").html(str);
                        if (data) {
                            for (a in data) {
                                str += '<option  value="'+data[a].city_id+'">'+data[a].city_name+'</option>';
                            }
                        }
                        $("#business_city_id").html(str);
                    },
                    dataType: 'text'
                });
            }
            else {
                var str = '<option value="0">请选择....</option>';
                $("#business_city_id").html(str);
                $("#business_city_id").html(str);
            }
        })
        $("#business_city_id").change(function () {
            var city_id = $("#business_city_id").val();
            if (city_id > 0) {
                $.ajax({
                    url: '/user/area',
                    data: {city_id: city_id},
                    type: 'POST',
                    success: function (data) {
                        var data = eval("(" + data + ")");
                        var str = '<option value="0">请选择....</option>';
                        $("#business_area_id").html(str);
                        if (data) {
                            for (a in data) {
                                str += '<option  value="'+data[a].area_id+'">'+data[a].area_name+'</option>';
                            }
                        }
                        $("#business_area_id").html(str);
                    },
                    dataType: 'text'
                });
            }
            else {
                var str = '<option value="0">请选择....</option>';
                $("#business_area_id").html(str);
                $("#business_area_id").html(str);
            }
        })
    });
</script>
<script type="text/javascript" src="/js/user.js"></script>
<style>
    .assort_list{display: none;}
</style>
{/literal}
<div class="help_center">

<div class="crumbs_tmg" style="padding-top:0;">当前位置：<a href="#">首页</a><i class="ffs">></i><a href="#">会员中心</a><i class="ffs">></i><span class="blue">公司信息</span></div>

    {include file = $smarty.const.APPLICATION_PATH|cat:"/application/views/menu_title.html"}

    <div class="user_content">
    	<h3 class="user_title j_ut">
        	<ul>
                <li class="curr">公司信息</li>
            </ul>
        </h3>
        
        
        <div class="receiving_address">

            <ul class="company_certification" style="padding-top:50px;padding-left:20px; display:block;">
                <form  action="" id="" name=""  method="" target="" enctype="multipart/form-data">
                <li class="ml77"><span class="fl mt5"><i class="orange">*</i>公司名称： </span>
                    <div class="popup_se w295">
                        <input name="userid" type="text" hidden />
                        <label></label>
                        <div class="popup_semg">
                            <select id="select1" name="business_id" class="business_id">
                                {foreach from=$invoice key=key item=item}
                                <option value="{$item.id}" {if $item.is_default eq 'Y'} selected {/if}>{$item.business_name}</option>
                                {/foreach}
                            </select>
                        </div>
                    </div>
                    <a href="#" class="add_company"><i></i>新增公司</a>
                </li>
                <li class="ml84"><span class="fl mt5">公司电话：</span><input class="popup_text w280" name="business_phone" type="text" value="" placeholder=""/></li>
                <li class="ml77"><span class="fl mt5"><i class="orange">*</i>主营品种：</span><input class="popup_text w280" name="main_variety" value="" type="text" placeholder=""/></li>
                <li class="ml97"><span class="fl mt5"><i class="orange">*</i>联系人：</span><input class="popup_text w280" name="contacts" value="" type="text" placeholder=""/></li>
                <li class="ml84"><span class="fl mt5"><i class="orange">*</i>联系手机：</span><input class="popup_text w280" name="mobile" value="" type="text" placeholder=""/></li>
                <li class="ml84"><span class="fl mt5">联系电话：</span><input class="popup_text w280" name="phone" value="" type="text" placeholder=""/></li>
                <li class="ml120"><span class="fl mt5">QQ：</span><input class="popup_text w280" name="qq" type="text" value="" placeholder=""/></li>
                <li class="ml84"><span class="fl mt5">公司地址：</span>
                    <div class="popup_se">
                        <label></label>
                        <select name="business_province_id" id="business_province_id" class="business_province_id">
                            <option value="0">省/市</option>
                            {foreach from=$province key=key item=item}
                            <option value="{$key}">{$item}</option>
                            {/foreach}
                        </select>
                    </div>
                    <div class="popup_se">
                        <label></label>
                        <select name="business_city_id" id="business_city_id" class="business_city_id">
                            <option value="0">城市</option>
                        </select>
                    </div>
                    <div class="clear_po">
                        <div class="popup_se w297 popl_20 mt20">
                            <label></label>
                            <select name="business_area_id" id="business_area_id" class="business_area_id">
                                <option value="0">区/县</option>
                            </select>
                        </div>
                    </div>
                    <div class="clear_po" style="padding-left:70px;">
                    <input class="popup_text w280 mt15" name="business_addr" type="text" placeholder="详细地址"/>
                    </div>
                </li>
                <li class="ml155"><label><input name="is_default" type="checkbox" value="Y" class="check_box mr5" />设为默认公司</label></li>
                <li class="ml155"><input type="button" class="ppfile_btn1 save_business" value="保   存"/></li>
                </form>
            </ul>
        </div>
    </div>
</div>





<script type="text/javascript">
    $(function(){
        $('.overlay-close,.popup_btn1').click(function(){
            $('.mui-dialog-mask').hide();
            $('.mui-dialog').hide();
        });

        $('.add_company').click(function(){
            $('.mui-dialog-mask').show();
            $('.mui-dialog').show();
        });
    });
</script>
<div class="mui-dialog-mask" style="display:none;"></div>
<div class="mui-dialog" style="width:500px;height:200px;display:none;">
    <a href="#" class="overlay-close"></a>
    <div class="mui-diglog-wrap">
        <div class="mui-dialog-header">新增公司</div>
        <div class="mui-dialog-body">
            <form class="" action="" id="myForm" name="myForm"  method="POST" target="_self" enctype="multipart/form-data">
            <ul class="mui_dl_list">
                <li>公司：<input class="popup_text w280" name="business_name" type="text" placeholder="请输入公司名称"/></li>
                <li class="popup_pl43 mt10"><input class="popup_btn popup_230 btn_submit" type="button" value="确 定"/><input class="popup_btn1 popup_230" type="button" value="取 消"/></li>
            </ul>
            </form>
        </div>
    </div>

    <div class="mui-dialog-skin"></div>

</div>



{include file = $smarty.const.APPLICATION_PATH|cat:"/application/views/footer.html"}